package com.ziytek.web.citizen;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * 线程池配置
 *
 * @author fenghx
 */
@Slf4j
@Configuration
public class PoolConfig {

    @Bean(name = "virtualThreadExecutor")
    public Executor virtualThreadExecutor() {

        //TaskExecutor.ofVirtual() 是 Spring 6.1+ 专为虚拟线程提供的API
        // 使用虚拟线程工厂创建执行器
        //return TaskExecutor.ofVirtual().name("vt-exec-").factory();

        //Executors.newVirtualThreadPerTaskExecutor() 是 JDK 21 标准API
        // 或者使用标准Executors方式：
        return Executors.newVirtualThreadPerTaskExecutor();

        // 使用Thread.ofVirtual()创建虚拟线程的执行器
        //return task -> Thread.ofVirtual().start(task);
    }
}
